
package com.bk.dao.impl;

import java.sql.SQLException;
import java.util.List;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import com.bk.dao.UserDao;
import com.bk.model.User;
import com.bk.utils.C3P0Util;

/**
 * 对user表进行操作
* @desc: bk
* @author: 千锋讲师张增强
* @createTime: 2017年7月3日 下午2:20:35
* @history:
* @version: v1.0
 */
public class UserDaoImpl implements UserDao{

	@Override
	public int add(String sql, Object... params) throws SQLException {
		QueryRunner qr=new QueryRunner(C3P0Util.getDataSource());
		return	qr.update(sql, params);
		
		
			
	}

	@Override
	public int delete(int uid) {
		
		//TODO
		return 0;
			
	}

	@Override
	public int update(String sql, Object... params) throws SQLException {
		QueryRunner qr=new QueryRunner(C3P0Util.getDataSource());
		//TODO
		return qr.update(sql, params);
			
	}

	@Override
	public User findById(int uid) {
		
		//TODO
		return null;
			
	}

	@Override
	public List<User> findByOthers(String sql, Object... params) throws SQLException {
		QueryRunner qr=new QueryRunner(C3P0Util.getDataSource());
		//TODO
		return qr.query(sql, new BeanListHandler<>(User.class), params);
			
	}

	@Override
	public User findByName(String uname) throws SQLException {
		QueryRunner qr=new QueryRunner(C3P0Util.getDataSource());
		
		
		return qr.query("select * from user where uname=?", new BeanHandler<>(User.class), uname);
			
	}

	@Override
	public List<User> findAll() {
		
		//TODO
		return null;
			
	}
	

}

	